package org.aliwo.callable;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * .
 *
 * @author Xu Yayuan
 * @date 2022/4/12
 */
public class CallableDemoMain {
//    public static void main(String[] args) {
//        CallableDemo callableDemo = new CallableDemo();
//        FutureTask<Object> futureTask = new FutureTask<>(callableDemo);
//        Thread thread = new Thread(futureTask);
//        thread.start();
//        System.out.println("主线程运行完毕 通过callable方式 实现多线程");
//        try {
//            System.out.println("获取返回值: " + futureTask.get());
//        } catch (InterruptedException | ExecutionException e) {
//            e.printStackTrace();
//        }
//    }

    public static void main(String[] args) {
        FutureTask<Object> futureTask = new FutureTask<>(()->{
            System.out.println(" lamda表达式方式通过 callable方式 实现多线程");
            return "返回值";
        });
        Thread thread = new Thread(futureTask);
        thread.start();
        System.out.println("主线程运行完毕 通过callable方式 实现多线程");
        try {
            System.out.println("获取返回值: " + futureTask.get());
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }
    }
}
